define([
    'jquery',
    'underscore',
    'backbone',
    //'flot',
    //'module/unit/models/UnitModel',
    //'module/unit/models/UnitCollection',    
    'text!module/dashboard/templates/main.html'
], function($, _, Backbone, /*flot, UnitModel, UnitCollection,*/ main) {

    var DashBoardController = Backbone.View.extend({
        el: $("#page"),
        initialize: function() {
            this.render();
        },
        events: {
        },
        render: function() {
            this.$el.html(main);


            $.get('server/api/operation/dh_p', function(data) {
                var data_plot1 = [];
                $.each(data, function(i, item) {
                    data_plot1.push([item.mes, parseFloat(item.total)]);
                });
                var plot2 = $.jqplot('chartdiv_purcharse', [data_plot1], {
                    series: [{renderer: $.jqplot.BarRenderer}, {xaxis: 'x2axis', yaxis: 'y2axis'}],
                    axesDefaults: {
                        tickRenderer: $.jqplot.CanvasAxisTickRenderer,
                        tickOptions: {
                            angle: 30
                        }
                    },
                    axes: {
                        xaxis: {
                            renderer: $.jqplot.CategoryAxisRenderer
                        },
                        x2axis: {
                            renderer: $.jqplot.CategoryAxisRenderer
                        },
                        yaxis: {
                            autoscale: true
                        },
                        y2axis: {
                            autoscale: true
                        }
                    }
                });

            }, "json");
//------------------------------------------------------------------------------
            $.get('server/api/operation/dh_s', function(data) {
                var data_plot = [[]];
                $.each(data, function(i, item) {
                    data_plot[0].push([parseInt(item.mes), parseFloat(item.total)]);
                });
                $.jqplot('chartdiv_sale', data_plot, {
                    title: 'Venta',
                    animate: true,
                    axes: {
                        xaxis: {
                            label: "Meses"
                        },
                        yaxis: {
                            label: "Soles",
                            tickOptions: {
                                formatString: 'S/%.2f'
                            }

                        }
                    }
                });
            }, "json");
            //------------------------------------------------------------------
            //ok
            /*var data = [
                ['Heavy Industry', 12], ['Retail', 9], ['Light Industry', 14],
                ['Out of home', 16], ['Commuting', 7], ['Orientation', 9]
            ];
            var plot1 = $.jqplot('chartdiv_purcharse_pie', [data], {
                seriesDefaults: {                    
                    renderer: jQuery.jqplot.PieRenderer,
                    rendererOptions: {                        
                        showDataLabels: true
                    }
                },
                legend: {show: true, location: 'e'}
            });*/
            //------------------------------------------------------------------------
            //ok
            /*var line1 = [14, 32, 41, 44, 40, 47, 53, 67];
            var plot1 = $.jqplot('chartdiv_sale_point', [line1], {
                title: 'Chart with Point Labels',
                seriesDefaults: {
                    showMarker: false,
                    pointLabels: {show: true}
                }
            });*/

        }



    });
    return DashBoardController;
});
